import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart';

class UserProvider with ChangeNotifier {
  bool _isLogin = false;
  Map _userInfo = {};

  bool get isLogin => _isLogin;
  Map get userInfo => _userInfo;

  // 设置用户信息
  void setUser(Map info) {
    _isLogin = true;
    _userInfo = info;
  }

  // 退出
  void doLogout() async {
    _isLogin = false;
    _userInfo = {};

    // 清理本地存储中的 token
    SharedPreferences p = await SharedPreferences.getInstance();
    p.remove('token');
    p.remove('expires_time');
  }
}